#include "stdafx.h"

#include "SolidMap.h"
#include "Player.h"

SolidMap gSolidMap;
SolidMap gHalfSolidMap;
SolidMap gLaddersMap;
SolidMap gMaleLaddersMap;
SolidMap gMaleHalfSolidMap;
SolidMap gOnlyMaleLaddersMap;
SolidMap gFemaleHalfSolidMap;

void SolidMap::Load(const char* filename)
{
	mImage.loadFromFile(filename);
}

bool SolidMap::IsSolid(int x, int y)
{
	if(x < 0) return false;
	if(y < 0) return false;
	if(x >= mImage.getSize().x) return false;
	if(y >= mImage.getSize().y) return false;

	if(this == &gMaleLaddersMap)
	{
		if(x < gMale.pos.x - VIEW_SIZE/2.0f) return false;
		if(x > gMale.pos.x + VIEW_SIZE/2.0f) return false;
	}
	if(this == &gMaleHalfSolidMap)
	{
		if(x < gMale.pos.x - VIEW_SIZE/2.0f) return false;
		if(x > gMale.pos.x + VIEW_SIZE/2.0f) return false;
	}
	if(this == &gFemaleHalfSolidMap)
	{
		if(y < gFemale.pos.y - VIEW_SIZE/2.0f) return false;
		if(y > gFemale.pos.y + VIEW_SIZE/2.0f) return false;
	}

	return mImage.getPixel(x, y).a > 0;
}

bool SolidMap::Vs(int x, int y, int width, int height)
{
	for(int i=x; i<x+width; i++)
	{
		for(int j=y; j<y+height; j++)
		{
			if(IsSolid(i, j))
				return true;
		}
	}

	return false;
}